import tensorflow as tf
from tensorflow.keras.datasets import mnist

# 加载数据
(X_train, y_train), (X_test, y_test) = mnist.load_data()

# 构建模型
model = tf.keras.Sequential([
    tf.keras.layers.Flatten(input_shape=(28, 28)),
    tf.keras.layers.Dense(128, activation='relu'),
    tf.keras.layers.Dense(10, activation='softmax')
])

model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])

# 训练模型
model.fit(X_train, y_train, epochs=5, validation_data=(X_test, y_test))